package com.cch.android.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.ViewFlipper;

import com.cch.android.activity.vf.ImageView;
import com.cch.android.activity.vf.ModelView;
import com.cch.android.activity.vf.MoreView;
import com.cch.android.activity.view.ad.MyAdView;
import com.cch.android.util.Constant;
import com.google.ads.AdRequest;
import com.google.ads.AdView;

public class ImageMainActivity extends Activity  {
	private ViewFlipper vf;
	private RadioGroup rg;
	private Context context;
	private AdView adView;
	private ModelView a;
	private ImageView b;
	private MoreView c;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_vf);
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		Constant.m_screenWidth = dm.widthPixels;
		Constant.m_screenHeight = dm.heightPixels;
		vf = (ViewFlipper) findViewById(R.id.vf);

		rg = (RadioGroup) findViewById(R.id.rg);
		context = this;
		a = new ModelView(this);
		b = new ImageView(this);
		c = new MoreView(this);
		
		vf.addView(a.makeNewView());
		vf.addView(b.makeNewView());
		vf.addView(c.makeNewView());
		 adView = new MyAdView(this);

		    LinearLayout layout = (LinearLayout)findViewById(R.id.main_ad_lay);

		    layout.addView(adView);

		    adView.loadAd(new AdRequest());
		
		
		rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(RadioGroup group, int checkedId) {
				int idx = -1;
				if (checkedId == R.id.rb01) {
					idx = 0;
				} else if (checkedId == R.id.rb02) {
					idx = 1;
				} else if (checkedId == R.id.rb03) {
					idx = 2;
				}
//				else if (checkedId == R.id.rb04) {
//					idx = 3;
//				} else if (checkedId == R.id.rb05) {
//					idx = 4;
//				}
				changeViewByHorizontalnAnim(vf, idx);
			}
		});
//        软件介绍：
//        一：“本地图片”可以读取本地的相册，将图片设置为桌面壁纸或者联系人头像、编辑成来电照片，可以根据自己的爱好操作，具体只需要对图片长按即可。
//        二：“本地功能”：美化图片、拼图、恶搞
//	      //1：美化图片功能有：调节色彩功能、剪切图片、背景虚化、设置边框、设置特效、添加文字
//	    剪切，旋转，锐化，调整饱和度，对比度，亮度;特效比如，LOMO，胶片，复古，老照片，反转色;图片上面加上文字，文字可以调整变形，变色，字的周围可以添加可爱边框;
//        
	        //2：拼图：能够自己DIY图片加一些搞笑，可爱的插图例如：眼镜；帽子；小的卡通人物;能够给图片加上边框，自由模板拼图。
	}       //3：恶搞：可以拉伸图片，弄出一些搞笑的效果

	@Override
	protected void onDestroy() {
		super.onDestroy();
		 adView.destroy();
		    super.onDestroy();
	}

	public void changeViewByHorizontalnAnim(ViewFlipper vf, int idx) {

		int currentIdx = vf.getDisplayedChild();
		if (idx == currentIdx) {
			return;
		}
		Animation leftIn = AnimationUtils.loadAnimation(context, R.anim.left_in);
		Animation leftOut = AnimationUtils.loadAnimation(context, R.anim.left_out);
		Animation rightIn = AnimationUtils.loadAnimation(context, R.anim.right_in);
		Animation rightOut = AnimationUtils.loadAnimation(context, R.anim.right_out);
		Animation in = null;
		Animation out = null;
		if (idx > currentIdx) {
			in = leftIn;
			out = leftOut;
		} else if (idx < currentIdx) {
			in = rightIn;
			out = rightOut;
		} else {
			return;
		}
		vf.setInAnimation(in);
		vf.setOutAnimation(out);
		vf.setDisplayedChild(idx);
	}

}
